var ServerSocket=require("./socket/SocketServer.js")
var SocketManager=Class.extend({
    _serverSocketDic:{},
    eventManager:null,
    init:function(eventManager){
        this.eventManager=eventManager;
    },
    listen:function(port,keyData){
        if(this._serverSocketDic[port])return;
        this._serverSocketDic[port]=new ServerSocket(this.eventManager);
        this._serverSocketDic[port].listen(port,keyData)
    },
    close:function(port){
        if(!this._serverSocketDic[port])return;
        this._serverSocketDic[port].close()
        delete this._serverSocketDic[port];
    },
    closeSocketByClientId:function(clientId,port){
        for(var key in this._serverSocketDic){
            this._serverSocketDic[key].closeSocketByClientId(clientId);
        }
    },
    sendMsg:function (port,clientId,msg) {
        if(this._serverSocketDic[port])
            this._serverSocketDic[port].sendMsg(clientId,msg);
    }
})

module.exports=SocketManager